package alp.starcode.framework.config;

import com.qiniu.common.Zone;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;

import java.util.Properties;

@Slf4j
@Data
//@Configuration
@AllArgsConstructor
public class QiNiuConfig {
    @Value("${qiniu.access-key}")
    private String accessKey = "-9l1j_S1UyI0vXKJ-N3jeuh8e1L0qoX7PwnalCZ-";
    @Value("${qiniu.secret-key}")
    private String secretKey = "XykHOuGxIPydKKlfwuDZiP5-LWd3lyPaXvt2lf2p";
    @Value("${qiniu.bucket}")
    private String bucket = "takeaway-center";
    @Value("${qiniu.zone-name}")
    private String zoneName = "zone2";

    @Value("${qiniu.domain-of-bucket}")
    private String domainOfBucket = "r367t7p8u.hn-bkt.clouddn.com";
    @Value("${qiniu.expire-in-seconds}")
    private long expireInSeconds = -1;

    private Zone zone;

    private static QiNiuConfig instance = new QiNiuConfig();

    private QiNiuConfig(){
        try {
            if(zoneName.equals("zone0")){
                zone = Zone.zone0();
            }else if(zoneName.equals("zone1")){
                zone = Zone.zone1();
            }else if(zoneName.equals("zone2")){
                zone = Zone.zone2();
            }else if(zoneName.equals("zoneNa0")){
                zone = Zone.zoneNa0();
            }else if(zoneName.equals("zoneAs0")){
                zone = Zone.zoneAs0();
            }else{
                throw new Exception("Zone对象配置错误！");
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public static QiNiuConfig getInstance(){
        return instance;
    }
    public static void main(String[] args) {
        System.out.println(QiNiuConfig.getInstance().getAccessKey());
    }
}